export default {
    getRandom(max, min = 1) {
        min = Math.ceil(min)
        max = Math.floor(max)
        return Math.floor(Math.random() * (max - min + 1)) + min //含最大值，含最小值
    },

    randomArr(arr) {
        for (var i = 0, len = arr.length; i < len; i++) {
            var a = parseInt(Math.random() * len)
            var temp = arr[a]
            arr[a] = arr[i]
            arr[i] = temp
        }
        return arr
    },

    isMobile() {
        const width = document.documentElement.clientWidth
        const result = width < 560
        return result
    },

    today() {
        const date = new Date()
        var myyear = date.getFullYear()
        var mymonth = date.getMonth() + 1
        var myweekday = date.getDate()
        var myhour = date.getHours()
        var myMinute = date.getMinutes()
        var mySecond = date.getSeconds()

        if (mymonth < 10) {
            mymonth = '0' + mymonth
        }
        if (myweekday < 10) {
            myweekday = '0' + myweekday
        }
        return myyear + '-' + mymonth + '-' + myweekday + ` ${myhour}:${myMinute}:${mySecond}`
    },

    saveHistory(data) {
        if (Object.prototype.toString.call(data) !== '[object Object]') {
            return
        }
        let history = localStorage.getItem('history')
        let historyObj
        if (history) {
            historyObj = JSON.parse(history)
        } else {
            historyObj = []
        }

        historyObj.unshift(data)
        localStorage.setItem('history', JSON.stringify(historyObj))
    },

    getHistory() {
        let history = localStorage.getItem('history')
        return JSON.parse(history)
    },

    clearHistory() {
        localStorage.removeItem('history')
    }
}
